X * I spent a long time writing this code & I hope that you respect this.
X * I give permission to alter the code, but not to copy or redistribute
X * it without my explicit permission. If you alter the code,
X * please document changes and send me a copy, so all can have it.
X * This code, to the best of my knowledge works well, but it is my first
X * 'C' program and should be treated as such. I disclaim any
X * responsibility for the codes actions (use at your own risk). I guess
X * I am saying "Happy gaming", and am trying not to get sued in the process.
X * Ed
X */
X
X#include "header.h"
X#include <ctype.h>
X
Xextern FILE *fnews;
X
Xextern short country;
Xextern int attr[MAPX][MAPY]; /*sector attactiveness*/
Xextern short occ[MAPX][MAPY];
Xextern short movecost[MAPX][MAPY];
Xint peace; /*is 8 if at peace, 12 if at war*/
X
X#ifdef NPC
Xnationrun()
X{
X int loop,armynum;
X int x,y,i,z;
X
X prep();
X
X /* is there an error*/
X if((sct[ntn[country].capx][ntn[country].capy].owner==country)&&(sct[ntn[country].capx][ntn[country].capy].designation!=DCAPITOL)){
X sct[ntn[country].capx][ntn[country].capy].designation=DCAPITOL;
X }
X
X /*go to war*/
X for(x=1;x<MAXNTN;x++) {
X /*if they at war with you go to war with them*/
X if(ntn[x].dstatus[country]>=WAR) {
X ntn[country].dstatus[x]=WAR;
X }
X /*else adjust diplomacy*/
X else if((ntn[country].dstatus[x]!=UNMET)&&(ntn[country].dstatus[x]!=JIHAD)&&(ntn[country].dstatus[x]!=CONFEDERACY)){
X if((ntn[x].tmil>4*ntn[country].tmil)&&(ntn[x].score>4*ntn[country].score)){
X if(rand()%3==0) ntn[country].dstatus[x]=WAR;
X else if(rand()%8==0)
X ntn[country].dstatus[x]=JIHAD;
X else ntn[country].dstatus[x]++;
X }
X /*if 2* mil and 2* score then not like them*/
X else if((ntn[x].tmil>2*ntn[country].tmil)&&(ntn[x].score>2*ntn[country].score)){
X if(ntn[country].dstatus[x]!=WAR)
X if(ntn[x].race==ntn[country].race){
X if(rand()%10==0) ntn[country].dstatus[x]++;
X }
X else if(rand()%3==0) ntn[country].dstatus[x]++;
X }
X /*adjust based on your status with them*/
X if(ntn[country].dstatus[x]!=WAR){
X if(ntn[x].dstatus[country]>ntn[country].dstatus[x]){
X if(rand()%3==0)
X ntn[country].dstatus[x]++;
X }
X else
X if(ntn[x].dstatus[country]<ntn[country].dstatus[x]){
X if(rand()%3==0)
X ntn[country].dstatus[x]--;
X }
X }
X if(rand()%4==0) ntn[country].dstatus[x]++;
X else if(rand()%3==0) ntn[country].dstatus[x]--;
X }
X else if((ntn[country].dstatus[x]==CONFEDERACY)&&(ntn[x].dstatus[country]==CONFEDERACY)&&(ntn[country].race==ntn[x].race)){
X if(ntn[x].active>=2) takeover(1,x);
X }
X }
X
X /*move units */
X /*are they at war with any normal countries*/
X peace=0;
X for(i=1;i<MAXNTN;i++) if(ntn[country].dstatus[i]>peace)
X peace=ntn[country].dstatus[i];
X
X if(peace<WAR){
X peace=8;
X pceattr();
X for(armynum=1;armynum<MAXARM;armynum++)
X if((ASOLD!=0)&&(ASTAT!=GARRISON)) armymove(armynum);
X }
X /*if war then attack &/or expand */
X else {
X peace=12;
X /*are they attacking or defending */
X for(x=0;x<MAXNTN;x++) if(ntn[country].dstatus[x]>HOSTILE){
X if(100*(ntn[country].tmil*(ntn[country].aplus+100))/((ntn[country].tmil*(ntn[country].aplus+100))+(ntn[x].tmil*(ntn[x].dplus+100)))>rand()%100){
X /*attacker*/
X for(armynum=1;armynum<MAXARM;armynum++)
X if((ASOLD>0)&&(ASTAT!=GARRISON)) ASTAT=ATTACK;
X atkattr();
X }
X /*defender*/
X else {
X for(armynum=1;armynum<MAXARM;armynum++)
X if((ASOLD>0)&&(ASTAT!=GARRISON)){
X if(ASOLD<350) ASTAT=DEFEND;
X else ASTAT=ATTACK;
X }
X defattr();
X }
X }
X
X for(armynum=1;armynum<MAXARM;armynum++)
X if((ASOLD!=0)&&(ASTAT!=GARRISON)) armymove(armynum);
X }
X
X /*redesignate sectors*/
X if(ntn[country].active!=1) for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
X if((sct[x][y].owner==country)&&(todigit(sct[x][y].vegitation)!=0)) npcredes(x,y);
X
X /*build forts in any cities*/
X if(ntn[country].active!=1) for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
X if(((sct[x][y].designation==DCITY)||(sct[x][y].designation==DCAPITOL))&&(sct[x][y].fortress<(sct[x][y].people%1000))&&(sct[x][y].fortress<5))
X sct[x][y].fortress++;
X
X /*redo mil*/
X /*rate position -- any cities with no garison get one*/
X if(ntn[country].active!=1) redomil();
X
X /*buy new powers and/or new weapons*/
X if(ntn[country].jewels > 2* JWL_MGK) {
X loop=0;
X for(armynum==0;armynum<=MAXPOWER;armynum++){
X if(magic(country,armynum)==1) i++;
X }
X /*maximum of nine powers for NPC nations*/
X if(i>NPCPOWERS) loop=1;
X while(loop==0){
X if((z=getmagic())!=1){
X fprintf(fnews,"2.\tnation %s gets magic power number %d\n",ntn[country].name,z);
X exenewmgk(z);
X ntn[country].jewels-=JWL_MGK;
X loop=1;
X }
X }
X
X }
X if(ntn[country].tiron > 4 * IRONORE * ntn[country].tmil){
X ntn[country].aplus+=1;
X ntn[country].dplus+=1;
X ntn[country].tgold-=2*IRONORE * ntn[country].tmil;
X }
X}
X
X/*calculate attractiveness when at peace*/
Xpceattr()
X{
X int x,y,temp;
X /*add around capital*/
X for(x=ntn[country].capx-2;x<=ntn[country].capx+2;x++)
X for(y=ntn[country].capy-2;y<=ntn[country].capy+2;y++)
X if(sct[x][y].owner==0) attr[x][y]+=80;
X /*add to attractiveness for unowned sectors*/
X for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) if(sct[x][y].owner==0) {
X /*temp stands for the distance from the capital*/
X temp=0;
X if(x>ntn[country].capx) temp+=x-ntn[country].capx;
X else temp+=ntn[country].capx-x;
X if(y>ntn[country].capy) temp+=y-ntn[country].capy;
X else temp+=ntn[country].capy-y;
X if(temp<3) attr[x][y]+=300-(50*temp);
X else if(temp<20) attr[x][y]+=100;
X }
X else if((sct[x][y].owner==NNOMAD)||(sct[x][y].owner==NBARBARIAN)||(sct[x][y].owner==NPIRATE)) attr[x][y]+=100;
X if(sct[ntn[country].capy][ntn[country].capy].owner!=country){
X attr[ntn[country].capy][ntn[country].capy]=1000;
X }
X}
X
X/*calculate attractiveness of attacking sectors*/
Xatkattr()
X{
X int nation,armie,x,y,x1,x2,Y1,y2;
X
X for(x=ntn[country].capx-2;x<=ntn[country].capx+2;x++)
X for(y=ntn[country].capy-2;y<=ntn[country].capy+2;y++)
X if(sct[x][y].owner==0) attr[x][y]+=80;
X
X for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) if((sct[x][y].owner==0)||(sct[x][y].owner==NNOMAD)||(sct[x][y].owner==NBARBARIAN)||(sct[x][y].owner==NPIRATE)) attr[x][y]+=100;
X
X /*adjust for each nation that you are at war with*/
X for(nation=1;nation<MAXNTN;nation++) if((ntn[country].dstatus[nation]>=WAR)&&(ntn[country].active!=0)){
X
X /*plus 1/2 men if in sector with their army*/
X /*defend your capital if occupied, +50 more if with their army*/
X for(armie=1;armie<MAXARM;armie++){
X if(ntn[nation].arm[armie].sold > 0) {
X
X attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold%10;
X
X if((ntn[nation].arm[armie].xloc<=ntn[country].capx+2)&&(ntn[nation].arm[armie].yloc<=ntn[country].capy+2)&&(ntn[nation].arm[armie].xloc>=ntn[country].capx-2)&&(ntn[nation].arm[armie].yloc>=ntn[country].capy-2)){
X attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold%5;
X if((rand()%3==0)&&(ntn[country].dstatus[nation]<WAR))
X ntn[country].dstatus[nation]++;
X if((ntn[nation].arm[armie].xloc==ntn[country].capx)&&(ntn[nation].arm[armie].yloc==ntn[country].capy)){
X if(ntn[country].dstatus[nation]==WAR)
X ntn[country].dstatus[nation]=JIHAD;
X if(ntn[nation].arm[armie].sold>2*ntn[country].arm[0].sold){
X attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold%2;
X }
X else attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold%5;
X }
X }
X }
X }
X
X /*plus 40 if next to their capital */
X for(x=ntn[nation].capx-1;x<=ntn[nation].capy+1;x++){
X for(y=ntn[nation].capy-1;y<=ntn[nation].capy+1;y++){
X if((x>0)&&(x<MAPX)&&(y>0)&&(y<MAPY)) attr[x][y]+=40;
X }
X }
X
X /*plus 100 if on their capital*/
X attr[ntn[nation].capx][ntn[nation].capy]+=100;
X
X /*+60 if between the two capitals*/
X if (ntn[nation].capx < ntn[country].capx){
X x1=ntn[nation].capx;
X x2=ntn[country].capx;
X }
X else {
X x1=ntn[country].capx;
X x2=ntn[nation].capx;
X }
X if (ntn[nation].capy < ntn[country].capy){
X Y1=ntn[nation].capy;
X y2=ntn[country].capy;
X }
X else {
X Y1=ntn[country].capy;
X y2=ntn[nation].capy;
X }
X for(x=x1;x<=x2;x++) for(y=Y1;y<=y2;y++) {
X if((x>0)&&(x<MAPX)&&(y>0)&&(y<MAPY)) attr[x][y]+=60;
X }
X
X /*for each sector +60 if their sector*/
X for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
X if((sct[x][y].owner==nation)&&(occ[x][y]==0))
X attr[x][y]+=100;
X else if(sct[x][y].owner==nation)
X attr[x][y]+=60;
X }
X if(sct[ntn[country].capy][ntn[country].capy].owner!=country){
X attr[ntn[country].capy][ntn[country].capy]=1000;
X }
X}
X
Xdefattr()
X{
X int nation,armie,x,y,x1,x2,y1,y2;
X
X for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) if((sct[x][y].owner==0)||(sct[x][y].owner==NNOMAD)||(sct[x][y].owner==NBARBARIAN)||(sct[x][y].owner==NPIRATE)) attr[x][y]+=100;
X
X for(x=ntn[country].capx-2;x<=ntn[country].capx+2;x++)
X for(y=ntn[country].capy-2;y<=ntn[country].capy+2;y++)
X if(sct[x][y].owner==0) attr[x][y]+=80;
X
X for(nation=1;nation<MAXNTN;nation++) if((ntn[nation].active!=0)&&(ntn[country].dstatus[nation]>=WAR)) {
X
X /*plus if near enemy army*/
X /*plus 30 if next to their army*/
X /*plus 60 if with their army*/
X for(armie=1;armie<MAXARM;armie++) if(ntn[nation].arm[armie].sold > 0) {
X
X attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold%10;
X
X if((ntn[nation].arm[armie].xloc<=ntn[country].capx+2)&&(ntn[nation].arm[armie].yloc<=ntn[country].capy+2)&&(ntn[nation].arm[armie].xloc>=ntn[country].capx-2)&&(ntn[nation].arm[armie].yloc>=ntn[country].capy-2)){
X attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold%5;
X if((rand()%3==0)&&(ntn[country].dstatus[nation]<WAR))
X ntn[country].dstatus[nation]++;
X if((ntn[nation].arm[armie].xloc==ntn[country].capx)&&(ntn[nation].arm[armie].yloc==ntn[country].capy)){
X if(ntn[country].dstatus[nation]==WAR)
X ntn[country].dstatus[nation]=JIHAD;
X if(ntn[nation].arm[armie].sold>2*ntn[country].arm[0].sold){
X attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold%2;
X }
X else attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold%5;
X }
X }
X }
X
X
X /*plus if strategic blocking sector*/
X /*+60 if between the two capitals*/
X if (ntn[nation].capx < ntn[country].capx){
X x1=ntn[nation].capx;
X x2=ntn[country].capx;
X }
X else {
X x1=ntn[country].capx;
X x2=ntn[nation].capx;
X }
X if (ntn[nation].capy < ntn[country].capy){
X y1=ntn[nation].capy;
X y2=ntn[country].capy;
X }
X else {
X y1=ntn[country].capy;
X y2=ntn[nation].capy;
X }
X
X for(x=x1;x<=x2;x++) for(y=y1;y<=y2;y++) {
X if((x>0)&&(x<MAPX)&&(y>0)&&(y<MAPY)) attr[x][y]+=60;
X }
X
X /*plus 80 if near your capital */
X for(x=ntn[country].capx-1;x<=ntn[country].capy+1;x++){
X for(y=ntn[country].capy-1;y<=ntn[country].capy+1;y++){
X if((x>0)&&(x<MAPX)&&(y>0)&&(y<MAPY)) attr[x][y]+=80;
X }
X }
X
X /*plus based on defensive value*/
X for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) {
X if(movecost[x][y]==1) attr[x][y] += 50;
X else if(movecost[x][y]<=3) attr[x][y] += 20;
X else if(movecost[x][y]<=5) attr[x][y] += 10;
X
X if((sct[x][y].designation==DCITY)&&((sct[x][y].owner==country)||(sct[x][y].owner==nation))){
X attr[x][y] += 50;
X }
X
X /* plus 60 if they own and unoccupied*/
X if((sct[x][y].owner==nation)&&(occ[x][y]==0)) attr[x][y]+=100;
X else if(sct[x][y].owner==nation) attr[x][y]+=60;
X }
X }
X
X if(sct[ntn[country].capy][ntn[country].capy].owner!=country){
X attr[ntn[country].capy][ntn[country].capy]=1000;
X }
X}
X#endif
X
X/*ntn 1 is nation you are updating*/
Xnewdip(ntn1,ntn2)
X{
X if(ntn[ntn1].active<2) {
X if(ntn[ntn1].dstatus[ntn2]==UNMET)
X ntn[ntn1].dstatus[ntn2]=NEUTRAL;
X }
X else if(ntn[ntn1].race==ntn[ntn2].race){
X if(rand()%5<3) ntn[ntn1].dstatus[ntn2]=FRIENDLY;
X else if(rand()%2==0) ntn[ntn1].dstatus[ntn2]=ALLIED;
X else ntn[ntn1].dstatus[ntn2]=NEUTRAL;
X }
X else switch(ntn[ntn1].race) {
X case DWARF:
X switch(ntn[ntn2].race) {
X case ELF:
X ntn[ntn1].dstatus[ntn2]=HOSTILE;
X break;
X case HUMAN:
X ntn[ntn1].dstatus[ntn2]=NEUTRAL;
X break;
X case ORC:
X default:
X ntn[ntn1].dstatus[ntn2]=WAR;
X break;
X }
X break;
X case ELF:
X switch(ntn[ntn2].race) {
X case DWARF:
X ntn[ntn1].dstatus[ntn2]=HOSTILE;
X break;
X case HUMAN:
X ntn[ntn1].dstatus[ntn2]=NEUTRAL;
X break;
X case ORC:
X default:
X ntn[ntn1].dstatus[ntn2]=WAR;
X break;
X }
X break;
X case ORC:
X switch(ntn[ntn2].race) {
X case HUMAN:
X ntn[ntn1].dstatus[ntn2]=NEUTRAL;
X break;
X case DWARF:
X case ELF:
X default:
X ntn[ntn1].dstatus[ntn2]=WAR;
X break;
X }
X break;
X case HUMAN:
X switch(ntn[ntn2].race) {
X case DWARF:
X case ELF:
X ntn[ntn1].dstatus[ntn2]=NEUTRAL;
X break;
X case ORC:
X ntn[ntn1].dstatus[ntn2]=HOSTILE;
X break;
X default:
X ntn[ntn1].dstatus[ntn2]=WAR;
X break;
X }
X break;
X default:
X ntn[ntn1].dstatus[ntn2]=WAR;
X break;
X }
X}
X
X/*destroy nation--special case if capital not owned by other nation*/
Xdestroy()
X{
X short armynum, nvynum;
X int i, x, y;
X fprintf(fnews,"1.\tDESTROY NATION %s",ntn[country].name);
X if(country!=sct[ntn[country].capx][ntn[country].capy].owner){
X fprintf(fnews,"\t(their capitol is owned by %s)\n",ntn[sct[ntn[country].capx][ntn[country].capy].owner].name);
X /*get +5% to combat skill*/
X ntn[sct[ntn[country].capx][ntn[country].capy].owner].aplus+=5;
X }
X else fprintf(fnews,"\t(they own their capitol)\n");
X
X ntn[country].active=0;
X for(armynum=0;armynum<MAXARM;armynum++) if(ASOLD>0) {
X if(ntn[sct[AXLOC][AYLOC].owner].race==ntn[country].race)
X sct[AXLOC][AYLOC].people+=ASOLD;
X ASOLD=0;
X }
X for(nvynum=0;nvynum<MAXNAVY;nvynum++) {
X NMER=0;
X NWAR=0;
X }
X for(i=0;i<MAXNTN;i++) {
X ntn[i].dstatus[country]=UNMET;
X ntn[country].dstatus[i]=UNMET;
X }
X
X /*if take them you get their gold*/
X if(country!=sct[ntn[country].capx][ntn[country].capy].owner){
X if(ntn[country].tgold>0) ntn[sct[ntn[country].capx][ntn[country].capy].owner].tgold+=ntn[country].tgold;
X if(ntn[country].jewels>0) ntn[sct[ntn[country].capx][ntn[country].capy].owner].jewels+=ntn[country].jewels;
X if(ntn[country].tiron>0) ntn[sct[ntn[country].capx][ntn[country].capy].owner].tiron+=ntn[country].tiron;
X if(ntn[country].tfood>0) ntn[sct[ntn[country].capx][ntn[country].capy].owner].tfood+=ntn[country].tfood;
X }
X
X /*if god destroys then kill all population*/
X if(country==sct[ntn[country].capx][ntn[country].capy].owner){
X for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) if(sct[x][y].owner==country) {
X sct[x][y].people=0;
X sct[x][y].owner=0;
X if(isdigit(sct[x][y].vegitation)!=0)
X sct[x][y].designation=DNODESIG;
X }
X }
X /*slowly take over and all people flee*/
X else if(ntn[sct[ntn[country].capx][ntn[country].capy].owner].race!=ntn[country].race){
X for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) if(sct[x][y].owner==country) {
X /*all kinds of refugees to neighboring countries*/
X flee(x,y,1);
X sct[x][y].people=0;
X sct[x][y].owner=0;
X if(isdigit(sct[x][y].vegitation)!=0)
X sct[x][y].designation=DNODESIG;
X }
X }
X /*else same race, so give all land to conqueror*/
X else {
X for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) if(sct[x][y].owner==country){
X sct[x][y].owner=sct[ntn[country].capx][ntn[country].capy].owner;
X if(isdigit(sct[x][y].vegitation)!=0)
X sct[x][y].designation=DNODESIG;
X }
X }
X return;
X}
X
Xmonster()
X{
X short nvynum,armynum;
X int x, y, done, j;
X
X /*move nomads randomly until within 2 of city then attack*/
X country=NNOMAD;
X for(armynum=0;armynum<MAXARM;armynum++) if(ASOLD>0){
X x=AXLOC+rand()%4-2;
X y=AYLOC+rand()%4-2;
X if((x>0)&&(x<MAPX)&&(y>0)&&(y<MAPY)&&(sct[x][y].altitude!=PEAK)&&(sct[x][y].altitude!=WATER)) {
X AXLOC=x;
X AYLOC=y;
X done=0;
X /*if owned & unoccupied you take & people flee*/
X if(sct[x][y].owner!=0) for(j=0;j<MAXARM;j++) if((ntn[sct[x][y].owner].arm[j].xloc==x)&&(ntn[sct[x][y].owner].arm[j].yloc==y)&&(ntn[sct[x][y].owner].arm[j].sold>0)) done=1;
X
X /*nomads take sector if done=0*/
X if(done==0){
X if(sct[x][y].owner==0)
X fprintf(fnews,"3.\tnomads take sector %d,%d\n",x,y);
X else fprintf(fnews,"3.\tnomads capture sector %d,%d\n",x,y);
X if(sct[x][y].owner!=0) flee(x,y,1);
X sct[x][y].owner=NNOMAD;
X sct[x][y].designation=DDEVASTATED;
X }
X }
X }
X else {
X /*place a new Nomad army*/
X x=(rand()%MAPX-8)+4;
X y=(rand()%MAPY-8)+4;
X if((rand()%4==0)&&(sct[x][y].altitude!=PEAK)&&(sct[x][y].altitude!=WATER)) {
X AXLOC=x;
X AYLOC=y;
X ASOLD=100+100*rand()%10;
X ASTAT=ATTACK;
X }
X }
X fprintf(fnews,"2.\t%s are updated\n",ntn[NPIRATE].name);
X /*if pirate fleet within 3 attack if outnumber any fleets */
X for(nvynum=0;nvynum<MAXNAVY;nvynum++){
X for(x=1;x<MAXNTN;x++) for(y=0;y<MAXNAVY;y++)
X if((ntn[x].nvy[y].xloc-NXLOC<2)&&(ntn[x].nvy[y].xloc-NXLOC>(-2))&&
X (ntn[x].nvy[y].yloc-NYLOC<2)&&(ntn[x].nvy[y].yloc-NYLOC>(-2))&&
X (sct[ntn[x].nvy[y].xloc][ntn[x].nvy[y].yloc].altitude==WATER)){
X NXLOC= ntn[x].nvy[y].xloc;
X NYLOC= ntn[x].nvy[y].yloc;
X }
X /*add one warship to random pirate fleet*/
X if((NWAR>0)&&(rand()%3==0)) NWAR++;
X }
X}
X
Xnpcredes(x,y)
X{
X int food;
X /*large enough for a city now?*/
X if(((sct[x][y].people*(CITYLIMIT+(ntn[sct[x][y].owner].tsctrs/3))>ntn[sct[x][y].owner].tciv)||((ntn[sct[x][y].owner].tciv<30000)&&(sct[x][y].people>1000)))&&(ntn[sct[x][y].owner].tfood>ntn[sct[x][y].owner].tciv*2)){
X if((rand()%2==0)&&((sct[x][y].designation==DFARM)||(sct[x][y].designation==DGOLDMINE)||(sct[x][y].designation==DMINE)))
X sct[x][y].designation=DCITY;
X }
X /*not large enough for city and not enough food*/
X else if((sct[x][y].designation==DCITY)&&(ntn[sct[x][y].owner].tfood<ntn[sct[x][y].owner].tciv*2)&&(todigit(sct[x][y].vegitation)>5)){
X sct[x][y].designation=DFARM;
X food=todigit(sct[x][y].vegitation)*sct[x][y].people;
X ntn[sct[x][y].owner].tfood += food;
X ntn[sct[x][y].owner].tgold += food*TAXFOOD/100-(sct[x][y].people * TAXCITY/100);
X }
X /*not large enough for a city but enough food*/
X else if((sct[x][y].designation==DCITY)&&(rand()%5==0)){
X sct[x][y].designation=DFARM;
X food=todigit(sct[x][y].vegitation)*sct[x][y].people;
X ntn[sct[x][y].owner].tfood += food;
X ntn[sct[x][y].owner].tgold += food*TAXFOOD/100-(sct[x][y].people * TAXCITY/100);
X }
X
X /*what if it is not a city*/
X if((sct[x][y].designation!=DCITY)&&(sct[x][y].designation!=DCAPITOL)) {
X sct[x][y].designation=DFARM;
X /*crisis situation -- need more food producers*/
X if(ntn[sct[x][y].owner].tfood<=2*ntn[sct[x][y].owner].tciv){
X if(sct[x][y].iron>5)
X sct[x][y].designation=DMINE;
X if((sct[x][y].gold>5)&&(sct[x][y].gold>sct[x][y].iron-2))
X sct[x][y].designation=DGOLDMINE;
X }
X /*non crisis situation -- need more food producers*/
X else {
X if(sct[x][y].iron>2)
X sct[x][y].designation=DMINE;
X if((sct[x][y].gold>2)&&(sct[x][y].gold>sct[x][y].iron-2))
X sct[x][y].designation=DGOLDMINE;
X }
X }
X}
X
Xredomil()
X{
X short x,y,armynum;
X int diff, i, free, done;
X
X /*make sure enough men in army 0 -- garrison duty in capital*/
X armynum=0;
X ASTAT=GARRISON;
X AXLOC=ntn[country].capx;
X AYLOC=ntn[country].capy;
X
X /*Ideally ASOLD(0)*MILINCAP=tmil*peace/10*/
X /*MILRATIO ratio mil:civ for non player countries*/
X /*MILINCAP ratio (mil in cap):mil for NPCs*/
X if(ASOLD*MILINCAP<.9*ntn[country].tmil*peace/10){
X /*too few soldiers on garrison*/
X /*diff is number to change mil in cap (>0)*/
X diff=(ntn[country].tmil*peace/(10*MILINCAP))-ASOLD;
X
X if(diff<ntn[country].tiron*10) diff=ntn[country].tiron*10;
X if(ntn[country].tgold<0L) diff=0;
X
X if(diff>sct[ntn[country].capx][ntn[country].capy].people)
X diff=sct[ntn[country].capx][ntn[country].capy].people/2;
X
X sct[ntn[country].capx][ntn[country].capy].people-=diff;
X ASOLD+=diff;
X ntn[country].tciv-=diff;
X ntn[country].tmil+=diff;
X ntn[country].tgold-=diff*ENLISTCOST;
X ntn[country].tiron-=diff*10;
X }
X /*else split garrison army if 1.25* needed number*/
X else if(ASOLD*MILINCAP>1.1*ntn[country].tmil*peace/10){
X diff=ASOLD-(1.25*ntn[country].tmil*peace/(10*MILINCAP));
X free=0;
X ASOLD-=diff;
X ntn[country].tciv-=diff;
X ntn[country].tmil+=diff;
X sct[ntn[country].capx][ntn[country].capy].people+=diff;
X }
X
X /*build ships and/or armies*/
X done=0;
X /*if tmil*MILRATIO<tciv build a single new army in the capital if possible*/
X if((ntn[country].tmil*MILRATIO<.8*ntn[country].tciv*peace/10)&&(ntn[country].tgold>0L)) for(armynum=1;armynum<MAXARM;armynum++) if((done==0)&&(ASOLD==0)) {
X done=1;
X ASOLD=(ntn[country].tciv*peace/(10*MILRATIO))-ntn[country].tmil;
X if(ASOLD>ntn[country].tiron*10) ASOLD= ntn[country].tiron/10;
X if(2*ASOLD>sct[ntn[country].capx][ntn[country].capy].people)
X ASOLD=sct[ntn[country].capx][ntn[country].capy].people/2;
X ntn[country].tiron-=ASOLD*10;
X AXLOC= ntn[country].capx;
X AYLOC= ntn[country].capy;
X ntn[country].tmil += ASOLD;
X ntn[country].tciv -= ASOLD;
X ntn[country].tgold-=ASOLD*ENLISTCOST;
X sct[AXLOC][AYLOC].people-=ASOLD;
X ASTAT= DEFEND;
X AMOVE=0;
X }
X
X /*disband ships and/or armies*/
X if(ntn[country].tmil*MILRATIO>1.2*ntn[country].tciv*peace/10){
X /*disband a pseudo-random army*/
X done=0;
X diff=ntn[country].tmil-(1.2*ntn[country].tciv*peace/(10*MILRATIO));
X for(armynum=1;armynum<MAXARM;armynum++)
X if((done==0)&&(sct[AXLOC][AYLOC].owner==country)&&((sct[AXLOC][AYLOC].gold>5)||(sct[AXLOC][AYLOC].iron>5))&&(rand()%5==0)&&(ASOLD<diff)){
X sct[AXLOC][AYLOC].people+=ASOLD;
X ntn[country].tmil -= ASOLD;
X ntn[country].tciv += ASOLD;
X ASOLD=0;
X if(ntn[country].tmil*MILRATIO>1.2*ntn[country].tciv*peace/10) done=1;
X }
X }
X
X /*resize armies */
X /*maximum npc army is 200 or tmil/20, minimum is 50*/
X for(armynum=1;armynum<MAXARM;armynum++){
X if((ASOLD>200)&&(ASOLD>ntn[country].tmil/20)) {
X free=0;
X for(i=1;i<MAXARM;i++){
X if((free==0)&&(ntn[country].arm[i].sold==0)){
X free=1;
X ASOLD/=2;
X ntn[country].arm[i].sold = ASOLD;
X ntn[country].arm[i].smove = AMOVE;
X ntn[country].arm[i].stat = DEFEND;
X ntn[country].arm[i].xloc = AXLOC;
X ntn[country].arm[i].yloc = AYLOC;
X }
X }
X }
X /*minimum npc army is 50, merge them*/
X else if(ASOLD<50) {
X free=0;
X for(i=1;i<MAXARM;i++){
X if((ntn[country].arm[i].sold>0)&&(ntn[country].arm[i].xloc==AXLOC)&&(ntn[country].arm[i].yloc==AYLOC)&&(i!=armynum)&&(free==0)){
X free=1;
X ntn[country].arm[i].sold += ASOLD;
X ASOLD=0;
X }
X }
X }
X }
X
X for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
X if((sct[x][y].owner==country)&&(sct[x][y].designation==DCITY)){
X free=0;
X for(armynum=0;armynum<MAXARM;armynum++){
X if((AXLOC==x)&&(AYLOC==y)) free=1;
X }
X /*move army in*/
X if(free==0){
X for(armynum=1;armynum<MAXARM;armynum++)
X if((abs(AXLOC-x)<=1)&&(abs(AYLOC-y)<=1))
X free=armynum;
X if(free>0){
X armynum=free;
X AXLOC=x;
X AYLOC=y;
X }
X }
X }
X}
END_OF_npc.c
if test 22830 -ne `wc -c <npc.c`; then
echo shar: \"npc.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 1 \(of 5\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 3 4 5 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 5 archives.
rm -f ark[1-9]isdone
else
echo You still need to unpack the following archives: